<?php

namespace app\admin\controller;

use think\Db;

class ConfigPersonal extends Common
{
    public function lists() {
        $key = input('key/s', '');
        $where = ['u.delete_time'=>0];
        $vals = [
            'fate_realavatar_limit'=>1,
            'fate_realname_limit'=>1,
            'unsmstip_switch'=>1,
            'voice_switch'=>0,
            'video_switch'=>0,
        ];
        if ($key) {
            $where['c.'.$key] = $vals[$key];
        }
        $this->assign('key', $key);

        $search_name = input('param.search_name');
        if ($search_name) {
            $where['c.user_id'] = $search_name;
        }
        $this->assign('search_name', $search_name);

        $pbanned = input('pbanned/d',0);
        if ($pbanned) {
            $where['u.is_banned'] = 0;
        }
        $this->assign('pbanned', $pbanned);

        $data = Db::name('config_personal')
            ->alias('c')
            ->join('user u', 'c.user_id=u.id')
            ->where($where)
            ->field('c.*,u.name,u.sex,u.is_banned')
            ->order('u.last_login_datetime desc')
            ->paginate(_getCachePages(), false, ['query' => request()->param()]);

        $page = $data->render();
        $this->assign('data', $data);
        $this->assign('page', $page);

        return $this->fetch();
    }
}